package com.infrared5.model
{
	import flash.utils.describeType;
	import flash.utils.getQualifiedClassName;

	public class Model
	{
		protected var _clazz:String;
		private static var _description:Object = {};
		
		public function Model()
		{
			_clazz = getQualifiedClassName( this );
		}
		
		public function get model():String
		{
			return _clazz;
		}
		
		[Transient]
		public function get description():Vector.<String>
		{
			if( Model._description[_clazz] == null )
			{
				var desc:Vector.<String> = Model._description[_clazz] = new Vector.<String>();
				var xml:XML = describeType( this );
				var variables:XMLList = xml..variable;
				var variable:XML;
				// Run through public variable declarations.
				for each( variable in variables )
				{
					desc[description.length] = variable.@name;
				}
				// Run through accessors.
				var accessors:XMLList = xml..accessor;
				for each( variable in accessors )
				{
					// Only include if readwrite.
					if( variable.@access == "readwrite" )
						desc[description.length] = variable.@name;
				}

			}
			return Model._description[_clazz];
		}
	}
}